#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Instruments/Bond.h>
#pragma unmanaged 
#include <ql\instruments\bonds\fixedratebond.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL::Times;
using namespace Cephei::QL;
using namespace Cephei::QL::Instruments;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Instruments { namespace Bonds {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IFixedRateBond
	public ref class CFixedRateBond  : 
            public CBond,
            public Cephei::QL::Instruments::Bonds::IFixedRateBond
	{
	protected: 
		boost::shared_ptr<QuantLib::FixedRateBond>* _ppFixedRateBond;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::FixedRateBond>* _phFixedRateBond;
#endif
		Object^ _FixedRateBondOwner;     // reference to object that manages the storage for this object
	internal:
		CFixedRateBond (UInt32 settlementDays, Double faceAmount, Cephei::QL::Times::ISchedule^ schedule, Cephei::Core::IVector<Cephei::QL::IInterestRate^>^ coupons, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Microsoft::FSharp::Core::FSharpOption<Double>^ redemption, Microsoft::FSharp::Core::FSharpOption<DateTime>^ issueDate, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ICalendar^>^ paymentCalendar, Cephei::QL::IPricingEngine^ QL_Pricer);
		CFixedRateBond (UInt32 settlementDays, Cephei::QL::Times::ICalendar^ couponCalendar, Double faceAmount, DateTime startDate, DateTime maturityDate, Cephei::QL::Times::IPeriod^ tenor, Cephei::Core::IVector<Double>^ coupons, Cephei::QL::Times::IDayCounter^ accrualDayCounter, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ accrualConvention, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Microsoft::FSharp::Core::FSharpOption<Double>^ redemption, Microsoft::FSharp::Core::FSharpOption<DateTime>^ issueDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ stubDate, Microsoft::FSharp::Core::FSharpOption<QL::Times::DateGeneration::RuleEnum>^ rule, Microsoft::FSharp::Core::FSharpOption<Boolean>^ endOfMonth, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ICalendar^>^ paymentCalendar, Cephei::QL::IPricingEngine^ QL_Pricer);
		CFixedRateBond (UInt32 settlementDays, Double faceAmount, Cephei::QL::Times::ISchedule^ schedule, Cephei::Core::IVector<Double>^ coupons, Cephei::QL::Times::IDayCounter^ accrualDayCounter, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Microsoft::FSharp::Core::FSharpOption<Double>^ redemption, Microsoft::FSharp::Core::FSharpOption<DateTime>^ issueDate, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ICalendar^>^ paymentCalendar, Cephei::QL::IPricingEngine^ QL_Pricer);
        CFixedRateBond (boost::shared_ptr<QuantLib::FixedRateBond>& childNative, Object^ owner);
        CFixedRateBond (QuantLib::FixedRateBond& childNative, Object^ owner);
        CFixedRateBond (CFixedRateBond^ copy);
        CFixedRateBond (PLATFORM::Type^ t);
#ifdef STRUCT
        CFixedRateBond (QuantLib::FixedRateBond childNative);
#endif       
#ifdef HANDLE
		CFixedRateBond (QuantLib::Handle<QuantLib::FixedRateBond>& childNative, Object^ owner);
		CFixedRateBond (QuantLib::Handle<QuantLib::FixedRateBond> childNative);
#endif
		virtual ~CFixedRateBond ();
		!CFixedRateBond ();

	internal:
		QuantLib::FixedRateBond& GetReference ();
		boost::shared_ptr<QuantLib::FixedRateBond>& GetShared ();
		QuantLib::FixedRateBond* GetPointer ();
        void SetFixedRateBond (boost::shared_ptr<QuantLib::FixedRateBond> native)
        {
            if (_ppFixedRateBond != NULL)
                delete _ppFixedRateBond;
            _ppFixedRateBond = new boost::shared_ptr<QuantLib::FixedRateBond> (native);
            SetBond (boost::dynamic_pointer_cast<QuantLib::Bond> (*_ppFixedRateBond));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::FixedRateBond>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Cephei::QL::Times::IDayCounter^ DayCounter 
        {
		    virtual Cephei::QL::Times::IDayCounter^ get () ;
        }
        property QL::Times::FrequencyEnum Frequency 
        {
		    virtual QL::Times::FrequencyEnum get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Instruments::Bonds::IFixedRateBond^>::typeid)]
	[FactoryFor(Cephei::QL::Instruments::Bonds::IFixedRateBond::typeid)]
	[FactoryFor(Cephei::QL::Instruments::Bonds::IFixedRateBond_Factory::typeid)]
	public ref class CFixedRateBond_Factory sealed : public IFixedRateBond_Factory
	{
	public:
        virtual IFixedRateBond^ Create (UInt32 settlementDays, Double faceAmount, Cephei::QL::Times::ISchedule^ schedule, Cephei::Core::IVector<Cephei::QL::IInterestRate^>^ coupons, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Microsoft::FSharp::Core::FSharpOption<Double>^ redemption, Microsoft::FSharp::Core::FSharpOption<DateTime>^ issueDate, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ICalendar^>^ paymentCalendar, Cephei::QL::IPricingEngine^ QL_Pricer);
        virtual IFixedRateBond^ Create (UInt32 settlementDays, Cephei::QL::Times::ICalendar^ couponCalendar, Double faceAmount, DateTime startDate, DateTime maturityDate, Cephei::QL::Times::IPeriod^ tenor, Cephei::Core::IVector<Double>^ coupons, Cephei::QL::Times::IDayCounter^ accrualDayCounter, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ accrualConvention, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Microsoft::FSharp::Core::FSharpOption<Double>^ redemption, Microsoft::FSharp::Core::FSharpOption<DateTime>^ issueDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ stubDate, Microsoft::FSharp::Core::FSharpOption<QL::Times::DateGeneration::RuleEnum>^ rule, Microsoft::FSharp::Core::FSharpOption<Boolean>^ endOfMonth, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ICalendar^>^ paymentCalendar, Cephei::QL::IPricingEngine^ QL_Pricer);
        virtual IFixedRateBond^ Create (UInt32 settlementDays, Double faceAmount, Cephei::QL::Times::ISchedule^ schedule, Cephei::Core::IVector<Double>^ coupons, Cephei::QL::Times::IDayCounter^ accrualDayCounter, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Microsoft::FSharp::Core::FSharpOption<Double>^ redemption, Microsoft::FSharp::Core::FSharpOption<DateTime>^ issueDate, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ICalendar^>^ paymentCalendar, Cephei::QL::IPricingEngine^ QL_Pricer);
    };
   
/*Cephei*/ } /*QL*/ } /*Instruments*/ } /*Bonds */}
